from app2 import appws
from flask_socketio import SocketIO, send, emit
import urllib.parse
from flask import Flask, render_template, request

socketio = SocketIO(appws, cors_allowed_origins='*')


@appws.route('/test1')
def index2():
    print("index2")
    return "test1"


@appws.get('/test2')
def index1():
    return "app ws2!"


@appws.route('/')
def index():
    return render_template('index.html')

@socketio.on('message')
def handle_message(message):
    message = urllib.parse.unquote(message)
    print(message)
    send(message, broadcast=True)


@socketio.on('connect', namespace='/chat')
def test_connect():
    emit('my response', {'data': 'Connected'})


@socketio.on('disconnect', namespace='/chat')
def test_disconnect():
    print('Client disconnected')



